package com.sinry.middleware.messages.api;

import com.sinry.message.domain.MessageDto;
import com.sinry.message.enums.RabbitQueue;
import com.sinry.middleware.messages.producer.MessageHandler;
import org.springframework.web.bind.annotation.*;

/**
 * @author linxinlei
 * @project sinry-cloud
 * @description 生产者api
 * @date 2022/8/7
 **/
@RestController
@RequestMapping("/producer")
public class ProducerMessageApi {

    private final MessageHandler messageHandler;

    public ProducerMessageApi(MessageHandler messageHandler) {
        this.messageHandler = messageHandler;
    }

    @PostMapping("/{rabbitQueue}/send")
    public void send(@PathVariable("rabbitQueue") RabbitQueue rabbitQueue, @RequestBody MessageDto messageDto) {
        messageHandler.with(rabbitQueue).ifPresent(message -> message.send(messageDto.getData()));
    }


}
